<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace app\member\model;

class Service extends \app\BaseModel
{
    protected $name = "massage_member_service";
    public function dataAdd($data)
    {
        $res = $this->insert($data);
        return $res;
    }
    public function dataUpdate($dis, $data)
    {
        $res = $this->where($dis)->update($data);
        return $res;
    }
    public function dataList($dis, $page)
    {
        $data = $this->where($dis)->order("status desc,id desc")->paginate($page)->toArray();
        return $data;
    }
    public function dataInfo($dis)
    {
        $data = $this->where($dis)->find();
        return !empty($data) ? $data->toArray() : [];
    }
    public function getMemberService($service_id)
    {
        $dis = ["a.service_id" => $service_id, "b.status" => 1];
        $data = $this->alias("a")->join("massage_member_level b", "a.level_id = b.id")->where($dis)->field("b.id,b.title")->group("a.id")->order("b.growth,a.id desc")->select()->toArray();
        return array_values($data);
    }
    public function getMemberServiceOne($service_id, $level_id = 0)
    {
        $dis = ["a.service_id" => $service_id, "b.status" => 1];
        if(!empty($level_id)) {
            $dis["b.id"] = $level_id;
        }
        $data = $this->alias("a")->join("massage_member_level b", "a.level_id = b.id")->where($dis)->field("b.title")->group("a.id")->order("b.growth,a.id desc")->find();
        return !empty($data) ? $data->toArray() : [];
    }
    public function getServiceMember($service_id, $level_id, $member_auth)
    {
        if($member_auth == 1) {
            if(!empty($level_id)) {
                $list = $this->getMemberServiceOne($service_id, $level_id);
                if(!empty($list)) {
                    $data["can_buy"] = 1;
                    return array_merge($data, $list);
                }
            }
            $list = $this->getMemberServiceOne($service_id);
            $data["can_buy"] = !empty($list) ? 0 : 1;
            $data = array_merge($data, $list);
        } else {
            $data["can_buy"] = 1;
        }
        return $data;
    }
    public function getUserMember($uniacid, $user_id)
    {
        $m_auth = new \app\member\info\PermissionMember($uniacid);
        $data["member_level"] = 0;
        $data["member_auth"] = 1;
        if(!$m_auth->pAuth()) {
            $data["member_auth"] = 0;
            return $data;
        }
        $config_model = new Config();
        $config = $config_model->dataInfo(["uniacid" => $uniacid]);
        if($config["status"] == 0) {
            $data["member_auth"] = 0;
            return $data;
        }
        $level_model = new Level();
        $member_level = $level_model->getUserLevel($user_id, 0);
        $data["member_level"] = !empty($member_level) ? $member_level["id"] : 0;
        return $data;
    }
}

?>